
import { ServerError } from "@/serve";

/**
 * 提取业务数据
 */
export async function processData(data: Response, options?: IProcessDataOptions) {
    if (options?.isExtractBody === false) {
        return data;
    } else {
        const res = await data.json();
        if (res || res === 0) {
            return res;
        } else {
            throw new ServerError(res?.message || '请求失败', res);
        }
    }
}

/**
 * 插件参数
 */
export interface IProcessDataOptions {
    /** 是否提取业务数据 */
    isExtractBody?: boolean;
}